package open.tech.dawn.web.core.controller;

import lombok.extern.slf4j.Slf4j;
import open.tech.dawn.core.error.ServiceException;
import open.tech.dawn.web.core.entity.LoginUser;
import open.tech.dawn.web.core.service.IAuthService;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class BaseController {

    @Autowired
    private IAuthService authService;

    /**
     * 获取DataEntity
     *
     * @return 返回
     */
    public String getUserId() {
        LoginUser user = authService.getUser();
        if (user == null) {
            throw new ServiceException("无权访问");
        }
        return user.getId();
    }


    public LoginUser getUser() {
        LoginUser user = authService.getUser();
        if (user == null) {
            throw new ServiceException("无权访问");
        }
        return user;
    }

}
